Post

Replies

Boosts

Views

Activity

Data race with Singleton in thread sanitizer
Hi,when I run my iOS app with thread sanitizer enabled I get tons of data race warnings when accessing an singleton:+ (SessionContext *)sharedSessionContext { static SessionContext *sharedInstance = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sharedInstance = [[SessionContext alloc] initSingleton]; }); return sharedInstance; }I can't spot the difference of the code above to the proposed pattern from WWDC 2016 session 412 (besides the usage of a function instead of a class function):Singleton *getSingleton() { static dispatch_once_t predicate; dispatch_once(&predicate, ^{ sharedInstance = [[self alloc] init]; }); return sharedInstance; }Error log:file:///Sources/***/Common/Context/SessionContext.m: runtime: Threading Issues: Data race in +[SessionContext sharedSessionContext] at __llvm_gcov_ctr.2583notice: Threading Issues: '__llvm_gcov_ctr.2583' is a global variable (0x10db63af8)Write of size 8 by thread 4#0 0x0000000108155267 in +[SessionContext sharedSessionContext] at /Sources/***/Common/Context/SessionContext.m:157#1 0x0000000107504b05 in __43-[LogonController loadData:]_block_invoke at /Sources/***//LogonController:288#2 0x00000001100d589c in __tsan::invoke_and_release_block(void*) ()#3 0x000000011aa9edb5 in _dispatch_client_callout ()Write of size 8 by thread 15#0 0x0000000108155267 in +[SessionContext sharedSessionContext] at Sources/***/Common/Context/SessionContext.m:157#1 0x000000010688aa84 in -[TitleView loadLogoLoggedIn] at /Sources/***/TitleView.m:260
2
0
925
Feb ’20
Watch -> iPhone handoff not working
Hi,I'm trying to get Handoff from a WatchKit app to an iOS app to work (again). It probably worked in the past with the older notification APIs.I validated Watch -> iPhone handoff works with some Apple supplied Apps.However when I open in our app the notification on the watch, nothing is shown on the iPhone (app switch..) screen.The Watchkit handoff code below is executed and no error is logged on the console- (void)willActivate { // This method is called when watch view controller is about to be visible to user [super willActivate]; [self startHandoff]; // ... } - (void)startHandoff { NSString *documentURL = self.news.url; NSLog(@"updating user activity to %@", documentURL); if (@available(watchOS 5.0, *)) { NSUserActivity *activity = [[NSUserActivity alloc] initWithActivityType:USER_ACTIVITY_TYPE]; activity.userInfo = @{HAND_OFF_DOCUMENT_URL_KEY : documentURL}; activity.title = self.news.headline; activity.eligibleForHandoff = YES; activity.needsSave = YES; // activity.targetContentIdentifier = documentURL; activity.requiredUserInfoKeys = [NSSet setWithObject:HAND_OFF_DOCUMENT_URL_KEY]; [self updateUserActivity:activity]; [activity becomeCurrent]; } else { // Fallback on earlier versions [self updateUserActivity:USER_ACTIVITY_TYPE userInfo:@{HAND_OFF_DOCUMENT_URL_KEY : documentURL} webpageURL:nil]; } }Originally the iOS App had the USER_ACTIVITY_TYPE just registered in the Info.plist under the NSUserActivityTypes key.I also added for testing code when registering the (working) push notification handler:- (void)registerForPushNotifications { UNNotificationCategory *newDocumentCategory = [UNNotificationCategory categoryWithIdentifier:PUSH_NOTIFICATION_TYPE actions:@[] // Default action is sufficient intentIdentifiers:@[] // SiriKit only options:UNNotificationCategoryOptionNone]; // UNNotificationCategoryOptionAllowAnnouncement UNNotificationCategory *handoverCategory = [UNNotificationCategory categoryWithIdentifier:USER_ACTIVITY_TYPE actions:@[] // Default action is sufficient intentIdentifiers:@[] // SiriKit only UNUserNotificationCenter *nc = [UNUserNotificationCenter currentNotificationCenter]; [nc setNotificationCategories:[NSSet setWithArray:@[newDocumentCategory, handoverCategory] ]]; [nc requestAuthorizationWithOptions:UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert completionHandler:^( BOOL granted, NSError *__nullable error ){ options:UNNotificationCategoryOptionNone];Any hints how I can debug?
3
0
657
Dec ’19